<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateSanitationSitesTable extends Migration
{
    /**
     * Run the migrations.
     *运营管理->基础数据导入->环卫部件导入->站点总表
     *
     * @return void
     */
    public function up()
    {
        Schema::create('sanitation_sites', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name')->comment('站点名称')->nullable();
            $table->string('number',20)->comment('编号')->nullable();
            $table->integer('category_id')->unsigned()->comment('站点类型id')->nullable();
            $table->foreign('category_id')->references('id')->on('sanitation_categories')->onDelete('set null');
            $table->string('address')->comment('地址')->nullable();
            $table->point('location')->comment('经纬度')->nullable();
            $table->integer('handle')->unsigned()->comment('日处理量')->nullable();
            $table->string('property_company',20)->comment('产权单位')->nullable();
            $table->string('operate_company',20)->comment('运营单位')->nullable();
            $table->integer('principal_id')->unsigned()->comment('负责人id')->nullable();
            $table->foreign('principal_id')->references('id')->on('employees')->onDelete('set null');
            $table->string('phone',20)->comment('电话')->nullable();
            $table->tinyInteger('status')->unsigned()->comment('厂房状态')->nullable();
            // $table->string('run_time')->comment('运营时间')->nullable();
            // $table->string('end_time')->comment('停运时间')->nullable();
            $table->integer('rfid')->unsigned()->comment('RFID绑定')->nullable();
            $table->softDeletes();
            $table->timestamps();
        });
        
        //附件中间表
        Schema::create('sanitation_site_files', function (Blueprint $table) {
            //字段定义
            $table->increments('id');
            $table->integer('sanitation_site_id')->unsigned()->comment('站点id')->nullable();
            $table->foreign('sanitation_site_id')->on('sanitation_sites')->references('id')->onDelete('set null');
            $table->BigInteger('file_id')->unsigned()->comment('图片所属的文件信息')->nullable();
            $table->foreign('file_id')->on('file_upload')->references('id')->onDelete('set null');
            $table->timestamps();
        });

    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('sanitation_site_files');
        Schema::dropIfExists('sanitation_sites');
    }
}
